<?php

namespace App\Http\Controllers\Backend;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Services\MenuService;

class MenuController extends Controller
{
    private $menuService;

    public function __construct(MenuService $menuService)
    {
        $this->menuService = $menuService;
    }
    
    public function index()
    {
        $menus = $this->menuService->getTree();
        $menuList = $this->menuService->getTreeList();
        return view('backend.menu.index', compact('menus', 'menuList'));
    }

    public function store(Request $request)
    {   
        $this->validate($request, [
            'name' => 'required',
            'parent_id' => 'required',
            'slug' => 'required'
        ]); 
        if($this->menuService->storeMenu($request->except('_token'))){
            flash('添加成功!')->success();
            return back();
        }


    }
}
